<?php

namespace app\saas\model;

use app\common\util\Tools;
use think\Model;

/**
 * Class Auth
 * @package app\saas\model
 * 设置表
 */
class trSetting extends Model
{
    protected $pk = 'id';
    protected $resultSetType = 'collection'; //申明结果集是数据集对象（collection），查询结果才能用toArray()方法转为数组
    protected $name = "saas_setting"; //表名

    public static function transferField($data){
        if(!$data){
            return [];
        }
        $data = Tools::transferFields($data);
        return $data;
    }

//    public static function toSave($data){
//        if(!empty($data)){
//            if(self::count()){ // 更新
//
//            }else{
//
//            }
//        }
//        return true;
//    }

    //获取多字段数据
    public static function getFields($field, $filter = [], $one = true, $toArray = true){ //缓存方法：缓存所有字段，只返回需要的字段
        if($one){
            $data = self::where($filter)->field($field)->find();
            return $data ? ($toArray ? self::transferField($data->toArray()) : Tools::transferFields($data->getData())) : [];
        }else{
            $data = self::where($filter)->field($field)->select();
            return $data ? ($toArray ? self::transferField($data->toArray()) : $data) : [];
        }
    }
}